import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import departmentsAsyncRoute from './modules/departments'
import settingAsync from './modules/settings'
import permissionsAsync from './modules/permissions'
import salarysAync from './modules/salarys'
import employeeAsync from './modules/employee'
import social_securitysAsync from './modules/social_securitys'
import approvalsAsync from './modules/approvals'
import attendanceAsync from './modules/attendance'
// 创建动态路由表
const asyncRoutes = [
  // 导入动态路由对象
  departmentsAsyncRoute,
  settingAsync, // 公司设置
  permissionsAsync, // 权限管理
  salarysAync, // 工资管理
  employeeAsync, // 员工
  social_securitysAsync, // 社保管理
  approvalsAsync, // 考勤管理
  attendanceAsync// 审批管理
]
// 静态路由表
export const constantRoutes = [
  {
    path: '/import',
    hidden: true, // 不显示到左侧菜单
    component: () => import('@/views/import/index.vue')

  },
  // 登录
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  // 首页
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },
  // 404
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes, ...asyncRoutes] // 最终生成的路由(将静态路由表和动态路由表合并到一起)
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
